/**
 *
 */
/**
 * AJAX注册
 */
function ajaxpost_signin() {
    if (document.getElementById('username').value == "") {
        alert("请输入昵称。");
        document.getElementById('username').focus();
        return (false);
    }
    if (document.getElementById('password').value == "") {
        alert("请输入密码。");
        document.getElementById('password').focus();
        return (false);
    }
    var usernameValue = $("#username").val();
    var passwordValue = $("#password").val();
    var checked = $("input[type='checkbox']").is(':checked');
    if (checked) {
        var rankVal = 10;
    } else {
        var rankVal = 0;
    }
    $.ajax({
        url: "post.php",
        type: "POST",
        async: true,
        timeout: 50000,
        dataType: "html",
        data: {
            post: "signin",
            username: usernameValue,
            password: passwordValue,
            rank: rankVal
        },
        success: function (data, textStatus, jqXHR) {
            if (data == "success") {
                alert("注册成功");
                window.location.href = "login.php";
            } else
                alert(data);
        },
        error: function (xhr, textStatus) {
            alert(xhr + textStatus);
        }
    });
}

/**
 * ajax登录
 *
 * @returns
 */
function ajaxpost_login(url, type) {
    if (document.getElementById('username').value == "") {
        alert("请输入用户名。");
        document.getElementById('username').focus();
        return (false);
    }
    if (document.getElementById('password').value == "") {
        alert("请输入密码。");
        document.getElementById('password').focus();
        return (false);
    }
    if (document.getElementById('verify').value == "") {
        alert("请输入验证码。");
        document.getElementById('verify').focus();
        return (false);
    }
    var usernameValue = $("#username").val();
    var passwordValue = $("#password").val();
    var verify = $("#verify").val();
    $.ajax({
        url: "post.php",
        type: "POST",
        async: true,
        timeout: 50000,
        dataType: "html",
        data: {
            post: "login",
            username: usernameValue,
            password: passwordValue,
            verify: verify
        },
        success: function (data, textStatus, jqXHR) {
            if (data == "success") {
                if (type == 1) {
                    alert("登录成功，跳转到登陆前页面！");
                    window.location.href = "jump.php?jback=" + url;
                } else {
                    alert("登录成功，跳转到论坛页面！");
                    window.location.href = url;
                }
            } else
                alert(data);
        },
        error: function (xhr, textStatus) {
            alert(xhr + textStatus);
        }
    });
}

/**
 * ajax登出
 *
 * @returns
 */
function ajaxpost_logout() {
    $.ajax({
        url: "post.php",
        type: "POST",
        async: true,
        timeout: 50000,
        dataType: "html",
        data: {
            post: "logout"
        },
        success: function (data, textStatus, jqXHR) {
            if (data == "success") {
                alert("登出成功");
                location.reload();
            } else
                alert(data);
        },
        error: function (xhr, textStatus) {
            alert(xhr + textStatus);
        }
    })
}

/**
 * ajax增加论坛区
 *
 * @returns
 */
function ajaxpost_addArea() {
    if (document.getElementById('addArea').value == "") {
        alert("请输入论坛区名。");
        document.getElementById('addArea').focus();
        return (false);
    }
    var areaName = $("#addArea").val();
    var areaOrder = $("#selectOrder option:selected").val();
    $.ajax({
        url: "post.php",
        type: "POST",
        async: true,
        timeout: 50000,
        dataType: "html",
        data: {
            post: "addArea",
            areaname: areaName,
            areaorder: areaOrder
        },
        success: function (data, textStatus, jqXHR) {
            if (data == "success") {
                alert("增加成功");
                window.location.href = "admin.php";
            } else
                alert(data);
        },
        error: function (xhr, textStatus) {
            alert(xhr + textStatus);
        }
    });
}

/**
 * 增加论坛板块
 *
 * @returns
 */
function ajaxpost_addForum() {
    var ue = UE.getEditor('container');
    var html = ue.getContent();
    var content = html;
    if (document.getElementById('addForum').value == "") {
        alert("请输入板块名。");
        document.getElementById('addForum').focus();
        return (false);
    }
    var forumName = $("#addForum").val();
    var forumAreaId = $("#addForumAreaId").val();
    $.ajax({
        url: "post.php",
        type: "POST",
        async: true,
        timeout: 50000,
        dataType: "html",
        data: {
            post: "addForum",
            forumname: forumName,
            forumareaid: forumAreaId,
            forumdesc: content
        },
        success: function (data, textStatus, jqXHR) {
            if (data == "success") {
                alert("增加成功");
                window.location.href = 'admin.php?type=area&id=' + forumAreaId;
            } else
                alert(data);
        },
        error: function (xhr, textStatus) {
            alert(xhr + textStatus);
        }
    });
}

function editAreaTitle() {
    var setEditaAreaName = $("#editAreaName").val();
    var setareaid = $("#areaid").val();
    $.ajax({
        url: "post.php",
        type: "POST",
        async: true,
        timeout: 50000,
        dataType: "html",
        data: {
            post: "editAreaName",
            areaname: setEditaAreaName,
            areaid: setareaid
        },
        success: function (data, textStatus, jqXHR) {
            if (data == "success") {
                alert("修改成功");
                //window.location.href = 'admin.php?type=area&id=' + setareaid;
            } else
                alert(data);
        },
        error: function (xhr, textStatus) {
            alert(xhr + textStatus);
        }
    });
}

function editForum() {
    var setEditaForumName = $("#editForumName").val();
    var setforumid = $("#forumid").val();
    var setauth_post = $("#auth_post").val();
    var auth_edit = $("#auth_edit").val();
    var ue = UE.getEditor('container');
    var html = ue.getContent();
    var content = html;
    $.ajax({
        url: "post.php",
        type: "POST",
        async: true,
        timeout: 50000,
        dataType: "html",
        data: {
            post: "editForum",
            forumname: setEditaForumName,
            auth_post: setauth_post,
            forumid: setforumid,
            auth_edit: auth_edit,
            forum_desc: content
        },
        success: function (data, textStatus, jqXHR) {
            if (data == "success") {
                alert("修改成功");
                //window.location.href = 'admin.php?type=area&id=' + setareaid;
            } else
                alert(data);
        },
        error: function (xhr, textStatus) {
            alert(xhr + textStatus);
        }
    });
}

function ajaxpost_addtopic() {
    var forumid = $("#forumid").val();
    var topic_title = $("#topic_title").val();
    var ue = UE.getEditor('container');
    var html = ue.getContent();
    var topic_content = html;
    var chacked = $("input[type='checkbox']").is(':checked');
    if (chacked) {
        var voteval = 1;
    } else
        var voteval = 0;
    $.ajax({
        url: "post.php",
        type: "POST",
        timeout: 50000,
        dataType: "html",
        data: {
            post: "addTopic",
            forumid: forumid,
            title: topic_title,
            content: topic_content,
            vote: voteval
        },
        success: function (data, textStatus, jqXHR) {
            if (data == "success") {
                alert("添加成功");
                window.location.href = 'forums.php?forumid=' + forumid + '&p=1';
            } else
                alert(data);
        },
        error: function (xhr, textStatus) {
            alert(xhr + textStatus);
        }
    });
}

//编辑帖子
function ajaxpost_edittopic(fid, tid, url) {
    var topicid = $("#topicid").val();
    var topic_title = $("#topic_title").val();
    var ue = UE.getEditor('container');
    var html = ue.getContent();
    var topic_content = html;
    var top = $("#settop").is(':checked');
    var chacked = $("#vote").is(':checked');
    var select_type = $("#select_type option:selected").val();
    var selectForumVal = $("#selectForum option:selected").val();
    if (chacked)
        var voteval = 1;
    else
        var voteval = 0;
    if (top)
        var settop = 1;
    else
        var settop = 0;
    $.ajax({
        url: "post.php",
        type: "POST",
        timeout: 50000,
        dataType: "html",
        data: {
            post: "editTopic",
            tid: tid,
            title: topic_title,
            content: topic_content,
            vote: voteval,
            selectType: select_type,
            settop: settop,
            selectForumVal: selectForumVal,
            fid: fid
        },
        success: function (data, textStatus, jqXHR) {
            if (data == "success") {
                alert("修改成功");
                window.location.href = "jump.php?jback=" + url;
            } else
                alert(data);
        }
        ,
        error: function (xhr, textStatus) {
            alert(xhr + textStatus);
        }
    })
    ;
}

//添加帖子回复
function ajaxpost_replytopic(uid) {
    var topicid = $("#topicid").val();
    var page = $("#page").val();
    var ue = UE.getEditor('container');
    var html = ue.getContent();
    var content = html;
    $.ajax({
        url: "post.php",
        type: "POST",
        timeOut: 50000,
        dataType: "html",
        data: {
            post: "replyTopic",
            topicid: topicid,
            content: content,
            replyuid: uid
        },
        success: function (data, textStatus, jqXHR) {
            if (data == "success") {
                alert("回复成功");
                window.location.href = 'topic.php?topicid=' + topicid + '&p=' + page;
            } else
                alert(data);
        },
        error: function (xhr, textStatus) {
            alert(xhr + textStatus);
        }
    });
}

//修改用户信息（用户名/密码）
function ajaxpost_change_users() {
    var type = $("#type").val();
    var g_uid = $("#uid").val();
    if (type == "username") {
        var s_username = $("#change_username").val();
        $.ajax({
            url: "post.php",
            type: "POST",
            timeOut: 50000,
            dataType: "html",
            data: {
                post: "change_username",
                uid: g_uid,
                username: s_username
            },
            success: function (data, textStatus, jqXHR) {
                if (data == "success") {
                    alert("修改成功");
                    window.location.href = 'home.php?mod=space&uid=' + g_uid;
                } else
                    alert(data);
            },
            error: function (xhr, textStatus) {
                alert(xhr + textStatus);
            }
        });
    }
    if (type == "password") {
        var g_password = $("#origin").val();
        var s_password = $("#change_password").val();
        $.ajax({
            url: "post.php",
            type: "POST",
            timeOut: 50000,
            dataType: "html",
            data: {
                post: "change_password",
                uid: g_uid,
                get_password: g_password,
                set_password: s_password
            },
            success: function (data, textStatus, jqXHR) {
                if (data == "success") {
                    alert("修改成功");
                    window.location.href = 'home.php?mod=space&uid=' + g_uid;
                } else
                    alert(data);
            },
            error: function (xhr, textStatus) {
                alert(xhr + textStatus);
            }
        });
    }
}

function ajaxpost_users() {
    var g_uid = getQueryVariable('uid');
    var ue = UE.getEditor('container');
    var html = ue.getContent();
    var content = html;
    var sexSelect = $("#sex option:selected").val();
    var dateValue = $("#birthday_date").val();
    var websiteValue = $("#website").val();
    var ownspeakValue = $("#ownspeak").val();
    var uidValue = $("#uid").val();
    var email = $("#email").val();
    $.ajax({
        url: "post.php",
        type: "POST",
        timeOut: 50000,
        dataType: "html",
        data: {
            post: "editusers",
            uid: uidValue,
            sex: sexSelect,
            date: dateValue,
            website: websiteValue,
            ownspeak: ownspeakValue,
            isignatur: content,
            email: email
        },
        success: function (data, textStatus, jqXHR) {
            if (data == "success") {
                alert("修改成功");
                window.location.href = 'home.php?mod=space&uid=' + g_uid + '&do=change';
            } else
                alert(data);
        },
        error: function (xhr, textStatus) {
            alert(xhr + textStatus);
        }
    });
}

//回贴状态改变：
function ajaxpost_edit_replyhide(postid) {
    //var postid = $("#post_id").val();
    $.ajax({
        url: "post.php",
        type: "POST",
        timeOut: 50000,
        dataType: "html",
        data: {
            post: "edit_replyhide",
            postid: postid
        },
        success: function (data, textStatus, jqXHR) {
            if (data == "hidden") {
                alert("隐藏成功");
                location.reload();
            } else if (data == "showed") {
                alert("恢复成功");
                location.reload();
            } else
                alert(data);
        },
        error: function (xhr, textStatus) {
            alert(xhr + textStatus);
        }
    });
}

function ajaxpost_edit_replydel(postid) {
    var r = confirm("确定删除？不可撤销");
    if (r)
        $.ajax({
            url: "post.php",
            type: "POST",
            timeOut: 50000,
            dataType: "html",
            data: {
                post: "edit_replydel",
                postid: postid
            },
            success: function (data, textStatus, jqXHR) {
                if (data == "success") {
                    alert("删除成功");
                    location.reload();
                } else
                    alert(data);
            },
            error: function (xhr, textStatus) {
                alert(xhr + textStatus);
            }
        });
}

//删除用户
function ajaxpost_delUser(uid) {
    $.ajax({
        url: "post.php",
        type: "POST",
        timeOut: 50000,
        dataType: "html",
        data: {
            post: "delUser",
            uid: uid
        },
        success: function (data, textStatus, jqXHR) {
            if (data == 'success') {
                alert('删除成功');
                window.location = "admin.php";
            } else {
                alert(data);
            }
        },
        error: function (xhr, textStatus) {
            alert(xhr + textStatus);
        }
    })
}

//修改用户权限
function ajaxpost_editrank(uid) {
    var select = $("#selectAll option:selected").val();
    var selectForum = $("#selectForumval").val();
    if (select == 2) {
        $.ajax({
            url: "post.php",
            type: "POST",
            timeOut: 50000,
            dataType: "html",
            data: {
                post: "editRank",
                uid: uid,
                select: select,
                selectForum: selectForum
            },
            success: function (data, textStatus, jqXHR) {
                if (data == "success") {
                    alert("修改成功");
                    window.location = "home.php?mod=space&uid=" + uid;
                } else
                    alert(data);
            },
            error: function (xhr, textStatus) {
                alert(xhr + textStatus);
            }
        });
    } else {
        $.ajax({
            url: "post.php",
            type: "POST",
            timeOut: 50000,
            dataType: "html",
            data: {
                post: "editRank",
                uid: uid,
                select: select
            },
            success: function (data, textStatus, jqXHR) {
                if (data == "success") {
                    alert("修改成功");
                    window.location = "home.php?mod=space&uid=" + uid;
                } else
                    alert(data);
            },
            error: function (xhr, textStatus) {
                alert(xhr + textStatus);
            }
        });
    }

}


//兑换徽章
function ajaxpost_buyMedal(uid, medalId) {
    $.ajax({
        url: "post.php",
        type: "POST",
        timeOut: 50000,
        dataType: "html",
        data: {
            post: "buyMedal",
            uid: uid,
            medalId: medalId
        },
        success: function (data, textStatus, jqXHR) {
            if (data == "success") {
                alert("兑换成功");
                window.location = "home.php?mod=space&uid=" + uid;
            } else if (data == "unenough") {
                alert("积分不足，兑换失败")
            } else if (data == "had") {
                alert("已经拥有，不能重复兑换");
            } else
                alert(data);
        },
        error: function (xhr, textStatus) {
            alert(xhr + textStatus);
        }
    });
}

//添加徽章
function ajaxpost_addMedal(uid) {
    var medalName = $("#medalName").val();
    var medalUrl = $("#medalUrl").val();
    var medalSale = $("#medalSale").val();
    $.ajax({
        url: "post.php",
        type: "POST",
        timeOut: 50000,
        dataType: "html",
        data: {
            post: "addMedal",
            medalName: medalName,
            medalUrl: medalUrl,
            medalSale: medalSale
        },
        success: function (data, textStatus, jqXHR) {
            if (data == "success") {
                alert("添加成功");
                window.location = "home.php?mod=space&uid=" + uid;
            } else
                alert(data);
        },
        error: function (xhr, textStatus) {
            alert(xhr + textStatus);
        }
    });
}

//删除用户徽章
function ajaxpost_delUserMedal(uid, mid) {
    $.ajax({
        url: "post.php",
        type: "POST",
        timeOut: 50000,
        dataType: "html",
        data: {
            post: "delUserMedal",
            uid: uid,
            mid: mid
        },
        success: function (data, textStatus, jqXHR) {
            if (data == "success") {
                alert("删除成功");
                window.location = "home.php?mod=space&uid=" + uid;
            } else
                alert(data);
        },
        error: function (xhr, textStatus) {
            alert(xhr + textStatus);
        }
    });
}

function ajaxpost_addCoin(uid) {
    var addCoins = $("#addCoins").val();
    $.ajax({
        url: "post.php",
        type: "POST",
        timeOut: 50000,
        dataType: "html",
        data: {
            post: "addCoins",
            uid: uid,
            addCoins: addCoins
        },
        success: function (data, textStatus, jqXHR) {
            if (data == "success") {
                alert("增加成功");
                window.location = "home.php?mod=space&uid=" + uid;
            } else
                alert(data);
        },
        error: function (xhr, textStatus) {
            alert(xhr + textStatus);
        }
    });
}

function ajaxpost_editCoinName(uid) {
    var scoreName = $("#scoreName").val();
    $.ajax({
        url: "post.php",
        type: "POST",
        timeOut: 50000,
        dataType: "html",
        data: {
            post: "editCoinName",
            scoreName: scoreName
        },
        success: function (data, textStatus, jqXHR) {
            if (data == "success") {
                alert("修改成功");
                window.location = "home.php?mod=space&uid=" + uid;
            } else
                alert(data);
        },
        error: function (xhr, textStatus) {
            alert(xhr + textStatus);
        }
    });
}

function ajaxpost_change_status(tid) {
    var statusType = $("#topic_status" + tid + " option:selected").val();
    $.ajax({
        url: "post.php",
        type: "POST",
        timeOut: 50000,
        dataType: "html",
        data: {
            post: "edittopicstatus",
            statusType: statusType,
            topicid: tid
        },
        success: function (data, textStatus, jqXHR) {
            if (data == "success") {
                // alert("修改成功");
                location.reload();
            } else
                alert(data);
        },
        error: function (xhr, textStatus) {
            alert(xhr + textStatus);
        }
    });
}

function ajaxpost_add_key() {
    if (document.getElementById('key_word').value == "") {
        alert("请输入关键字。");
        document.getElementById('key_word').focus();
        return (false);
    }
    var key = $("#key_word").val();
    var change = $("#change_word").val();
    $.ajax({
        url: "post.php",
        type: "POST",
        timeOut: 50000,
        dataType: "html",
        data: {
            post: "add_key",
            key: key,
            change: change
        },
        success: function (data, textStatus, jqXHR) {
            if (data == "success") {
                // alert("修改成功");
                location.reload();
            } else
                alert(data);
        },
        error: function (xhr, textStatus) {
            alert(xhr + textStatus);
        }
    });
}

function ajaxpost_del_key(id) {
    var r = confirm('确定删除？');
    if (r) {
        $.ajax({
            url: "post.php",
            type: "POST",
            timeOut: 50000,
            dataType: "html",
            data: {
                post: "del_key",
                id: id
            },
            success: function (data, textStatus, jqXHR) {
                if (data == "success") {
                    // alert("修改成功");
                    location.reload();
                } else
                    alert(data);
            },
            error: function (xhr, textStatus) {
                alert(xhr + textStatus);
            }
        });
    } else
        location.reload();
}


function ajaxpost_changeBgColor(uid) {
    document.getElementById('changeColor').click();
    var color = $("#changeColor").val();
    document.body.style.background = color;
    //alert(color);
    $.ajax({
        url: "post.php",
        type: "POST",
        timeout: 50000,
        dataType: "html",
        data: {
            post: "changeBg",
            uid: uid,
            color: color
        },
        success: function (data, textStatus, jqXHR) {
            if (data == "success") {
                //alert("1");
                //location.reload();
            } else
                alert(data);
        },
        error: function (xhr, textStatus) {
            alert(xhr + textStatus);
        }
    });
}

//赞
function ajax_addLike(postid) {
    $.ajax({
        url: "post.php",
        type: "POST",
        timeout: 50000,
        dataType: "html",
        data: {
            post: "addLike",
            postid: postid
        },
        success: function (data, textStatus, jqXHR) {
            $("#like").text(data);
        },
        error: function (xhr, textStatus) {
            alert(xhr + textStatus);
        }
    });
}

function ajaxpost_loginout(uid, type) {
    if (type == 1) {
        var r = confirm("确定封禁？");
        if (r) {
            var time = prompt("封锁时间至（单位：分钟）后", 10);
            if (time != null && time != "") {
                time = parseInt(time);
                if (isNaN(time)) {
                    alert("请输入数字！");
                } else if (time < 1 || time > 15768000) {
                    alert("请输入正确的数字");
                } else {
                    if (time)
                        var print_time = time * 60;
                    $.ajax({
                        url: "post.php",
                        type: "POST",
                        timeout: 50000,
                        dataType: "html",
                        data: {
                            post: "loginout",
                            time: print_time,
                            uid: uid
                        },
                        success: function (data, textStatus, jqXHR) {
                            if (data == "success") {
                                alert("下线成功");
                                location.reload();
                            } else
                                alert(data);
                        },
                        error: function (xhr, textStatus) {
                            alert(xhr + textStatus);
                        }
                    });
                }
            }
        }
    } else if (type == 0) {
        var r = confirm("确定还原？");
        if (r) {
            $.ajax({
                url: "post.php",
                type: "POST",
                timeout: 50000,
                dataType: "html",
                data: {
                    post: "loginout",
                    time: 0,
                    uid: uid
                },
                success: function (data, textStatus, jqXHR) {
                    if (data == "success") {
                        alert("还原成功");
                        location.reload();
                    } else
                        alert(data);
                },
                error: function (xhr, textStatus) {
                    alert(xhr + textStatus);
                }
            });
        }
    }
}

function ajaxpost_lzl(tid, pid, uid) {
    if (document.getElementById("lzl" + pid).value == "") {
        alert("请输入回复。");
        document.getElementById("lzl" + pid).focus();
        return (false);
    }
    var addLzlpid = $("#lzl" + pid).val();
    $.ajax({
        url: "post.php",
        type: "POST",
        timeout: 50000,
        dataType: "html",
        data: {
            post: "lzlPost",
            lzlcontent: addLzlpid,
            tid: tid,
            pid: pid,
            uid: uid
        },
        success: function (data, textStatus, jqXHR) {
            if (data == "success") {
                alert("回复成功");
                location.reload();
            } else
                alert(data);
        },
        error: function (xhr, textStatus) {
            alert(xhr + textStatus);
        }
    });
}